package com.shoux.api.web.controller;

import com.shoux.api.web.entity.CompanySxLogEntity;
import com.shoux.api.web.entity.MsgEntity;
import com.shoux.api.web.entity.query.CommonQuery;
import com.shoux.api.web.service.CompanySxLogService;
import com.shoux.api.web.service.QuestionnaireInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhouzhe
 * @since 2021-07-22
 */
@Slf4j
@Api(tags = "春风授信企业接口")
@RestController
@RequestMapping("swqysx")
public class QyxxController {

    @Autowired
    private QuestionnaireInfoService questionnaireInfoService;
    @Autowired
    private CompanySxLogService comapnySxLogService;
    @ApiOperation("提交信息")
    @PostMapping("submitQuestnrInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commonQuery", value = "请求表单", dataType = "CommonQuery"),
//            @ApiImplicitParam(name = "reqType", value = "提交类型(0:企业基本信息, 1:问卷信息)", dataType = "int")
    })
    public MsgEntity submitQuestnrInfo(@RequestBody CommonQuery commonQuery){
        CompanySxLogEntity sxLogEntity = new CompanySxLogEntity();
        sxLogEntity.setCompanyName(commonQuery.getQymc());
        sxLogEntity.setCreditCode(commonQuery.getShtyxydm());
        sxLogEntity.setCreateTime(LocalDateTime.now());
        sxLogEntity.setParameter(commonQuery.toString());
        MsgEntity msgEntity = questionnaireInfoService.submitQuestnrInfo(commonQuery);
        sxLogEntity.setResult(msgEntity.toString());
        sxLogEntity.setEndTime(LocalDateTime.now());
        try {
            comapnySxLogService.save(sxLogEntity);
        }catch (Exception e){
            e.printStackTrace();
            log.error("授信额度日志记录入库异常");
        }
        return msgEntity;
    }
}
